//
//  HJCHomeNavigationBar.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/26.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit

class HJCHomeNavigationBar: UINavigationBar {
    
    ///懒加载tipLabel
    lazy var tipLable : UILabel = {
        let tipLabel = UILabel()
        tipLabel.backgroundColor = UIColor.orangeColor()
        tipLabel.textColor = UIColor.whiteColor()
        tipLabel.textAlignment = NSTextAlignment.Center
        return tipLabel
        }()
    
    override func awakeFromNib() {
        //最底层添加提示label
  
        insertSubview(tipLable, atIndex: 0)
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
       //设置提示label的大小
        if tipLable.frame == CGRectZero{
            tipLable.frame = CGRectOffset(bounds, 0, -2*bounds.height)
        }
    }
//
    ///设置tipLabel的动画
    func tipLabelAnimation(text:String){
        
         let rect = tipLable.frame
         tipLable.text = text
         UIView.animateWithDuration(1, animations: { () -> Void in
            //重复一次
            UIView.setAnimationRepeatCount(1)
            //自动恢复位置
            UIView.setAnimationRepeatAutoreverses(true)
            self.tipLable.frame = CGRectOffset(self.bounds, 0, self.bounds.height)
         }) { (_) -> Void in
            //恢复初始位置
            self.tipLable.frame = rect
        }
    
    }

}
